package b3.widget.home.operation
{
	import b3.model.*;
	import b3.net.*;
	import b3.scene.home.*;
	import b3.widget.*;
	import b3.widget.basic.*;
	
	import flash.events.MouseEvent;
	
	public class OperationRemove extends BasicIcon
	{
		private var buildingModel:BuildingModel;
		
		public function OperationRemove(buildingModel:BuildingModel)
		{
			this.buildingModel = buildingModel;
			var IconBgr:Class = ResourceHelper.getInstance().getClassByName("OperationRemove");
			super(IconBgr, "拆除", 1, true);
			disableMouseOverTip();
			addEventListener(MouseEvent.CLICK, onMouseClick);
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			HomeScene.getInstance().centerInfoPane.showOperationTip("OperationRemove", "拆除违章建筑", 0x00AAFF);
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			HomeScene.getInstance().centerInfoPane.clear();
		}
		
		private function onMouseClick(event:MouseEvent):void
		{
			var messageBox:MessageBox = new MessageBox("确定要移除当前建筑？", true);
			messageBox.x = -messageBox.width / 2;
			messageBox.y = -messageBox.height / 2;
			messageBox.setOKCall(removeBuilding);
			WidgetManager.getInstance().popOut([messageBox], true);
		}
		
		private function removeBuilding():void
		{
			var townModel:TownModel = HomeScene.getInstance().getCurrentTown().owner.townModel;
			townModel.removeBuilding(buildingModel.id);
		}
	}
}